

# from rest_framework.generics import ListAPIView,RetrieveAPIView
from rest_framework.viewsets import ModelViewSet
from orders.models import OrderInfo
from meiduo_admin.serializers.order_serializers import *
from meiduo_admin.custom_paginations import MyPage

# class OrderView(ListAPIView):
class OrderView(ModelViewSet):
    queryset = OrderInfo.objects.all()
    serializer_class = OrderSimpleModelSerializer
    pagination_class = MyPage

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return self.queryset.filter(order_id__contains=keyword)
        return self.queryset.all()



    def get_serializer_class(self):
        # list -- OrderSimpleModelSerializer
        # retrieve -- OrderDetailModelSerializer
        if self.action == 'list':
            return self.serializer_class
        elif self.action == 'retrieve':
            return OrderDetailModelSerializer

        return self.serializer_class